<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col>
      <strong v-if="is_Root"
        ><i class="el-icon-office-building"></i>{{ node_data.name }}</strong
      >
      <span v-else>{{ node_data.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ node_data.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartment"
                >添加子部门</el-dropdown-item
              >
              <el-dropdown-item v-if="!is_Root" @click.native="editDepartment"
                >编辑子部门</el-dropdown-item
              >
              <el-dropdown-item v-if="!is_Root" @click.native="delDepartment"
                >删除子部门</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartment } from "../../../api/departments";
export default {
  props: {
    node_data: {
      type: Object,
      required: true,
    },
    is_Root: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    async delDepartment() {
      try {
        // console.log(1);
        await this.$confirm("确认删除");
        await delDepartment(this.node_data.id);
        this.$message.success("删除成功");
        this.$emit("delDepartment");
      } catch (error) {
        // console.log(error);
      }
    },

    addDepartment() {
      this.$emit("addDepartment", this.node_data);
    },
    editDepartment() {
      this.$emit("editDepartment", this.node_data);
    },
  },
};
</script>

<style>
</style>